<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>支付宝配置</title>
    <meta name="keywords" content="支付宝配置">
    <meta name="description" content="支付宝配置">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">


</head>

<body class="gray-bg">
    
    <div class="wrapper wrapper-content animated fadeInRight">
    <form action="lightpay/alipayConfigList" method="post" id="alipayConfigForm">
        <div class="row">

        	<div class="col-sm-12">
        		<table class="table table-hover">
        			<tr>
        				<td>
							 <input value="${param.userName}" name="userName" class="form-control" placeholder="请输入用户名">
        				</td>
        				<td>
        					<select class="form-control" name="state" id="state" data-placeholder="搜索引擎">
					            <option value="">状态</option>
					            <option value="01" <c:if test="${param.state == '01'}">selected</c:if>>启用</option>
					            <option value="00" <c:if test="${param.state == '00'}">selected</c:if>>禁用</option>
					        </select>
        				</td>
        				<td>
        					<button type="button" class="btn btn-primary" onclick="searchs();">检索</button>
        				</td>
        			</tr>
        		</table>
			</div> 
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<a class="btn btn-primary " href="javascript:add();" target="_self">新增</a>
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                	<th>用户</th>
                                    <th>app_id</th>
                                    <th>商户ID</th>
                                    <th>支付类型</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
							<c:forEach items="${page.list}" var="ac" varStatus="vs">
                            	<tr>
                                    <td>${ac.userName }</td>
									<td>${ac.appId }</td>
									<td>${ac.sellerId }</td>
									<td>${ac.payType }</td>
									<td>
									${ac.state eq '01' ?'启用':'禁用'}
									</td>
                                    <td>
                                    <a class="fa view-info" id ="${ac.id }"
                                    data-id="${ac.id }"
                                    data-appid="${ac.appId }"
                                    data-sellerid="${ac.sellerId }"
                                    data-username="${ac.userName }"
                                    data-paytype="${ac.payType }"
                                    data-appprivatekey="${ac.appPrivateKey }"
                                    data-alipaypublickey="${ac.alipayPublicKey }"
                                    data-encryptkey="${ac.encryptKey }"
                                    >查看</a>
                                    <a class="fa edit-info">编辑</a>                            
                                    <c:choose>
                                    	<c:when test="${ac.state eq '01' }">
                                    	<a class="fa" href="javascript:updateState('${ac.id}','00');" title="禁用">禁用</a>
                                    	</c:when>
                                    	<c:otherwise>
                                    	<a class="fa" href="javascript:updateState('${ac.id}','01');" title="启用">启用</a>
                                    	</c:otherwise>
                                    </c:choose>
                                    
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        
                        <jsp:include page="/WEB-INF/jsp/page.jsp">
                        	<jsp:param value="alipayConfigForm" name="form"/>
                        </jsp:include>
                    </div>
                </div>
            </div>
        </div>
        
        </form>
        </div>
        	<div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
                  <div class="modal-dialog modal-lg">
                      <div class="modal-content">
                          <div class="modal-header">
                              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                              <h4 class="modal-title">支付宝配置</h4>
                          </div>
                          <div class="modal-body">

                    <div class="form-horizontal">
                    		<input type="hidden" id="id" value="">
                    		
                    		<div class="form-group">
                                <label class="col-sm-2 control-label">用户名</label>

                                <div class="col-sm-10">
                                    <input type="text" id="userName" name="userName" value="" class="form-control">
                                </div>
                            </div>
                    		
                            <div class="form-group">
                                <label class="col-sm-2 control-label">app_id</label>

                                <div class="col-sm-10">
                                    <input type="text" id="appId" name="appId" value="" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商户ID</label>

                                <div class="col-sm-10">
                                    <input type="text" id="sellerId" name="sellerId" value="" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">AES秘钥</label>

                                <div class="col-sm-10">
                                    <input type="text" id="encryptKey" name="encryptKey" value="" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">私钥</label>

                                <div class="col-sm-10">
                                	<textarea class="form-control" id="appPrivateKey" name="appPrivateKey" style="resize:none;height: 100px"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">支付宝公钥</label>

                                <div class="col-sm-10">
                                	<textarea class="form-control" id="alipayPublicKey" name="alipayPublicKey" style="resize:none;height: 100px"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">支付类型</label>

                                <div class="col-sm-10">
                                	<select class="form-control" name="payType" id="payType" data-placeholder="支付类型">
					            		<option value="page">二维码支付</option>
					        		</select>
                                </div>
                            </div>

                </div>
            </div>

                          <div class="modal-footer">
                              <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                              <button type="button" class="btn btn-primary" id="configSave">保存</button>
                          </div>
                      </div>
                  </div>
            </div>
        
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/content.min.js?v=1.0.0"></script>
    
    <script src="static/templet/js/iframe.min.js"></script>
    <script type="text/javascript">
    
    function searchs(){
    	$("#alipayConfigForm").submit();
    }
    
	var isInsert = false;
    $('.view-info').click(function(){
	   
	    $obj = $(this);
	    $('#id').val($obj.data('id'));
	    $('#userName').attr("readonly",true);
	    $('#userName').val($obj.data('username'));
	    $('#appId').attr("readonly",true);
		$('#appId').val($obj.data('appid'));
		$('#sellerId').attr("readonly",true);
		$('#sellerId').val($obj.data('sellerid'));
		$('#encryptKey').attr("readonly",true);
		$('#encryptKey').val($obj.data('encryptkey'));
		$('#appPrivateKey').attr("readonly",true);
		$('#appPrivateKey').val($obj.data('appprivatekey'));
		$('#alipayPublicKey').attr("readonly",true);
		$('#alipayPublicKey').val($obj.data('alipaypublickey'));
		$('#payType').attr("readonly",true);
		$('#payType').val($obj.data('paytype'));
		$('#configSave').hide();
		$('#myModal5').modal();
   	}); 

    $('.edit-info').click(function(){
    	isInsert = false;
 	    $obj = $(this).parent().find('.view-info');
 	    $('#id').val($obj.data('id'));
	    $('#userName').attr("readonly",true);
	    $('#userName').val($obj.data('username'));
	    $('#appId').attr("readonly",false);
		$('#appId').val($obj.data('appid'));
		$('#sellerId').attr("readonly",false);
		$('#sellerId').val($obj.data('sellerid'));
		$('#encryptKey').attr("readonly",false);
		$('#encryptKey').val($obj.data('encryptkey'));
		$('#appPrivateKey').attr("readonly",false);
		$('#appPrivateKey').val($obj.data('appprivatekey'));
		$('#alipayPublicKey').attr("readonly",false);
		$('#alipayPublicKey').val($obj.data('alipaypublickey'));
		$('#payType').attr("readonly",false);
		$('#payType').val($obj.data('paytype'));
		$('#configSave').show();
 		$('#myModal5').modal();
    }); 
    

    
    function add(){
    	isInsert = true;
    	$('#id').val('');
    	$('#userName').attr("readonly",false);
  	    $('#userName').val('');
  	    $('#appId').attr("readonly",false);
  	  	$('#appId').val('');
  	    $('#sellerId').attr("readonly",false);
 		$('#sellerId').val('');
 		$('#encryptKey').attr("readonly",false);
		$('#encryptKey').val('');
 		$('#appPrivateKey').attr("readonly",false);
 		$('#appPrivateKey').val('');
 		$('#alipayPublicKey').attr("readonly",false);
 		$('#alipayPublicKey').val('');
 		$('#payType').attr("readonly",false);
 		$('#payType').val('page');
    	$('#configSave').show();
 		$('#myModal5').modal();
    }

	$('#configSave').click(function(){
		var id = $.trim($('#id').val());
		var userName = $.trim($('#userName').val());
		var appId = $.trim($('#appId').val());
		var sellerId = $.trim($('#sellerId').val());
		var encryptKey = $.trim($('#encryptKey').val());
		var appPrivateKey = $.trim($('#appPrivateKey').val());
		var alipayPublicKey = $.trim($('#alipayPublicKey').val());
		var payType = $.trim($('#payType').val());
		var params = {};
		if(!isInsert){
			if(id == ''){
				layer.msg('请选择支付宝配置', {icon: 1});
				return;
			}
			params.id = id;
		}
		
		if(userName == ''){
			layer.msg('用户不能为空', {icon: 1});
			return;
		}
		if(appId == ''){
			layer.msg('appId不能为空', {icon: 1});
			return;
		}
		if(sellerId == ''){
			layer.msg('商户ID不能为空', {icon: 1});
			return;
		}
		if(encryptKey == ''){
			layer.msg('AES秘钥不能为空', {icon: 1});
			return;
		}
		if(appPrivateKey == ''){
			layer.msg('私钥不能为空', {icon: 1});
			return;
		}
		if(alipayPublicKey == ''){
			layer.msg('支付宝公钥不能为空', {icon: 1});
			return;
		}
		if(payType == ''){
			layer.msg('请选择支付类型', {icon: 1});
			return;
		}

		
		params.userName = userName;
		params.appId = appId;
		params.sellerId = sellerId;
		params.encryptKey = encryptKey;
		params.appPrivateKey = appPrivateKey;
		params.alipayPublicKey = alipayPublicKey;
		params.payType = payType;
		params.isInsert = isInsert;

		$.ajax({
			url:'lightpay/save',
			data:JSON.stringify(params),
			type:'post',
			contentType:'application/json',
			dataType:'json',
			success: function(data) {
				var result = data.result;
				if(result.state == '1'){
    				layer.msg('保存成功', {icon: 1});
    				location.reload();
    			}else{

    				layer.msg(result.message, {icon: 1});
    			}
	        },
	        error: function (data){
	        	layer.msg('保存失败', {icon: 1});
	        }
		})

	
	});
    
    function edit(userId){
    	parent.layer.open({
    	    type: 2,
    	    title: '用户',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/edit?userId='+userId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }

    
    function deleteUser(userId){
    	parent.layer.confirm('确定删除吗？', {
    	    btn: ['确定'], //按钮
    	    shade: false //不显示遮罩
    	}, function(){
    		$.get("user/deleteUser?id="+userId,function(data,status){
        		
        		if(status == 'success'){
        			var result = data.result;
        			if(result.state == '1'){
        				parent.layer.msg('删除成功', {icon: 1});
        				location.reload();
        			}else{
 
        				parent.layer.msg(result.message, {icon: 1});
        			}
        		}
        	})
    	});
    	
    }
    
    function updateState(id, state){
    	parent.layer.confirm('确定更改吗？', {
    	    btn: ['确定'], //按钮
    	    shade: false //不显示遮罩
    	}, function(){
    		$.post("lightpay/updateState",{id:id, state:state},function(data,status){
        		
        		if(status == 'success'){
        			var result = data.result;
        			if(result.state == '1'){
        				parent.layer.msg('修改成功', {icon: 1});
        				location.reload();
        			}else{
 
        				parent.layer.msg(result.message, {icon: 1});
        			}
        		}
        	})
    	});
    	
    }
    </script>

</body>

</html>